package com.losdun.common.utils.uuid;

import java.util.Random;

/**
 * @Description
 * @Author Sword.Ye
 * @Date 2025/10/17
 **/
public class CodeUtils {

    /**
     * 生成指定长度的数字验证码
     * @param length
     * @return
     */
    public static String generateNumberCode(int length) {
        // 验证长度合法性
        if (length <= 0) {
            throw new IllegalArgumentException("验证码长度必须大于0");
        }

        Random random = new Random();
        StringBuilder codeBuilder = new StringBuilder();

        for (int i = 0; i < length; i++) {
            // 生成0-9之间的随机数字
            int num = random.nextInt(10);
            codeBuilder.append(num);
        }

        return codeBuilder.toString();
    }
}
